package com.example.flow.util;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class JsUtils {

    public static Object eval(String str){
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("JavaScript");

        try {
            // 执行JavaScript代码并获取结果
            Object result = engine.eval(str);
            // 输出结果
            System.out.println("JavaScript execution result: " + result);

            return result;
        } catch (ScriptException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
       Object result= eval("23 > 32");
    }
}
